package com.yellow.car.impl;

import com.yellow.car.api.TruckApi;
import com.yellow.car.entity.Truck;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
@Slf4j
public class TruckApiImpl implements TruckApi {
    private static Truck truck1;
    private static Truck truck2;
    private static List<Truck> truckList = new ArrayList<>();

    @Override
    public void init() {
        //初始化货车
        truck1 = new Truck(3, 20);
        truck2 = new Truck(3, 20);
        truckList.add(truck1);
        truckList.add(truck2);
    }

    @Override
    public List<Truck> getTruckList() {
        return truckList;
    }

    @Override
    public double getSpeed(Truck truck) {
        double speed = Math.round(1.0 / truck.getSpeed());
        return speed;
    }
}
